package com.d0318;

import org.omg.CORBA.TIMEOUT;

import java.util.concurrent.TimeUnit;

public class Resource {
    public synchronized void f(){
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName()+"f() is Running");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
    public synchronized void g(){
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName()+"g() is Running");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
    public synchronized void h(){
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName()+"h() is Running");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

    public static void main(String[] args) {
        Resource resource=new Resource();
        new Thread(()->resource.f()).start();
        new Thread(()->resource.f()).start();
        resource.h();
    }
}
